home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / os2 / nortutil.zip / src / NewSpeak / newspeak.x
Text File  |  1994-04-13  |  20KB  |  675 lines

  1. %{    -*- Mode:Fundamental -*-
  2. /*
  3.  *    newspeak.l
  4.  *    Lex filter to transform plain English into NewSpeak.
  5.  *    Copyright (c) 1991 Jamie Zawinski <jwz@lucid.com>.
  6.  *    Permission granted for noncommercial use and redistribution.
  7.  *
  8.  *    To compile:
  9.  *
  10.  *    flex newspeak.l
  11.  *    cc -O -o newspeak lex.yy.c
  12.  *    rm lex.yy.c
  13.  *
  14.  *    This must be compiled with "flex", not normal "lex".  Lex has
  15.  *    some builtin, unchangable limits which this program exceeds.
  16.  *    This has been verified to work with flex version 2.3.7, and
  17.  *    may not work with flex version 2.3.6.
  18.  *
  19.  *    You can get 'flex' by anonymous FTP to prep.ai.mit.edu, or 
  20.  *    anywhere else you get GNU software.
  21.  *
  22.  *    Run this like so:  "newspeak < some-text-file | more"
  23.  *
  24.  *    There are some design notes near the end.  Suggestions and
  25.  *    improvements to this code are more than welcome.  
  26.  *    Hail Big Brother!
  27.  *---------------------------------------------------------------------------
  28.  */
  29. #include <stdio.h>
  30.  
  31. unsigned int fcounter = 0;
  32.  
  33. #define Y0    yytext[0]
  34. #define Y1    yytext[1]
  35. #define Y2    yytext[2]
  36. #define Y3    yytext[3]
  37. #define C    caseify
  38. #define C1    caseify1
  39.  
  40. #define CAP(string)    capstring(0, (string),0)
  41. #define WCAP(string)    capstring(Y0,(string),1)
  42.  
  43. #define COMP(string1,string2)    compstring(0, (string1),(string2),0)
  44. #define WCOMP(string1,string2)    compstring(Y0,(string1),(string2),1)
  45.  
  46. #define    DUMP()            printf("%s",yytext)
  47. %}
  48.  
  49. %e 8000
  50. %p 9000
  51. %n 2000
  52. %k 3000
  53. %a 5000
  54. %o 4000
  55.  
  56. W    (([     ]?\n[     ]*)|[     ]|[\"'`])
  57. ES    [.,;:!?/]
  58. EW    ({W}|{ES}|"'")
  59.  
  60. YOUNG    (([Yy]oung|[Ss]mall|[Ll]ittle){W})
  61. DEAD    (([Dd]ead|[Dd]eceased){W})
  62. THE    ([Tt]he{W}?)
  63. ANDOR    ({W}(([Aa]nd)|([Oo]r)){W}?)
  64. COLOR    (red|green|blue|yellow|cyan|magenta|purple|orange|mauve|pink|turquoise|brown|gr[ae]y)
  65.  
  66. %%
  67.  
  68. %{
  69.     /******************************
  70.      *        PLUSwords          *
  71.      ******************************/
  72. %}
  73.  
  74. [Qq]uite{EW}/[A-Za-z][A-Za-z]            CAP("plus");
  75. [Rr]ather{EW}/[A-Za-z][A-Za-z][A-Za-z]        CAP("plus");
  76. [Kk]ind{EW}of{EW}/[A-Za-z][A-Za-z][A-Za-z]    CAP("plus");
  77. [Kk]inda{EW}/[A-Za-z][A-Za-z][A-Za-z]        CAP("plus");
  78. [Mm]ore{W}than{W}a{W}(little|bit){W}        CAP("plus");
  79. [Pp]ro-                        CAP("plus");
  80.  
  81. [Hh]undreds{W}of{W}[Tt]housands            |
  82. [Hh]undreds{ANDOR}[Tt]housands            |
  83. [Hh]undreds{W}if{W}not{W}[Tt]housands        |
  84. [Tt]housands                    |
  85. [Mm]illions                    CAP("doubleplusmany");
  86.  
  87. [Dd]ozens                    CAP("many");
  88. [Hh]undreds                    CAP("plusmany");
  89.  
  90. ([Bb]right|[Ll]ight|[Ii]ntense){W}/{COLOR}    CAP("plus");
  91. ([Dd]im|[Ff]aded|[Dd]ark|[Pp]ale){W}/{COLOR}    CAP("plusun");
  92.  
  93. [Ee]very                    DUMP();
  94. [Vv]ery{W}                    |
  95. [Rr]eally{W}                    |
  96. [Tt]erribly{W}                    |
  97. [Aa]wesome({W})?                |
  98. [Aa]wfully{W}                    CAP("doubleplus");
  99.  
  100. [Ww]hopping{EW}                    CAP("plusbig");
  101.  
  102. "O.K."                        |
  103. [Aa]ll({W})?[Rr]ight                |
  104. [Oo][Kk][Aa][Yy]                CAP("plusgood");
  105. {W}OK/{W}                    WCAP("plusgood");
  106.  
  107. ([Tt]oo|[Oo]verly|[Tt]hat){W}[Mm]uch        CAP("plusmuch");
  108.  
  109. {W}[Bb]ad/{EW}        WCAP("ungood");
  110. {W}[Pp]oor/{EW}        WCAP("ungood");
  111. {W}[Ll]ame/{EW}        WCAP("ungood");
  112. {W}[Pp]itiful/{EW}    WCAP("ungood");
  113. {W}[Nn]asty/{EW}    WCAP("plusungood");
  114. {W}[Hh]orrid/{EW}    WCAP("doubleplus ungood");
  115. {W}[Hh]orrible/{EW}    WCAP("doubleplus ungood");
  116. {W}[Aa]wful/{W}        WCAP("doubleplus ungood");
  117. {W}[Ee]vil/{W}        WCAP("doubleplus ungood");
  118.  
  119. %{
  120.     /******************************
  121.      *         Titles          *
  122.      ******************************/
  123. %}
  124.  
  125. {W}[Ss]ir/{EW}        WCAP("citizen");
  126. {W}[Mm]r"."/{EW}    WCAP("brother");
  127. [Mm]ister/{EW}        CAP("brother");
  128. [Mm]adame?        CAP("sister");
  129. {W}[Mm]iss/{EW}        WCAP("sister");
  130. [Mm]a"'"?am/{EW}    CAP("sister");
  131. {W}[Mm]r?s"."/{EW}    WCAP("sister");
  132. Mrs/{EW}        CAP("sister");
  133.  
  134. {YOUNG}?[Cc]hildren                CAP("young citizens");
  135. {YOUNG}?[Bb]oys{ANDOR}[Gg]irl/s            CAP("young citizens");
  136. {YOUNG}?([Kk]id|[Gg]irl|[Bb]oy|[Cc]hild)/{EW}    CAP("young citizen");
  137.  
  138. [Ff]ellow        CAP("citizen");
  139.  
  140. [Nn]on{W}?"-"?citizen    CAP("unperson");
  141. [Nn]on{W}?"-"?member    CAP("unperson");
  142. [Cc]riminal/s?        CAP("unperson");
  143. {DEAD}(man|woman)    CAP("unperson");
  144. {DEAD}(men|women)    CAP("unpersons");
  145.  
  146. [Ii]n{W}[Pp]erson    DUMP();
  147.  
  148. {W}[Uu]ser        WCOMP("party ","worker");
  149. [Ss]tudent        COMP("party ","worker");
  150. [Cc]itizen/s?{EW}    COMP("party ","worker");
  151. [Pp]erson/s?{EW}    COMP("party ","worker");
  152. [Pp]eople        COMP("party ","workers");
  153.  
  154. [Ss]enator        |
  155. [Cc]ongressman        |
  156. [Ss]upervisor        |
  157. [Pp]rofessor        printf("Inner Party Member");
  158. [Pp]rof"."/{EW}        printf("Inner Party Member");
  159. [Pp]rof/{EW}        printf("Inner Party Member");
  160.  
  161. Representative/s?    printf("Inner Party Member");
  162. representatives        printf("Inner Party Members");
  163.  
  164. [Ww]hite{W}[Cc]ollar        |
  165. [Uu]pper{W}[Cc]lass        COMP("inner ","party");
  166. [Mm]iddle{W}[Cc]lass        CAP("party");
  167. [Bb]lue{W}[Cc]ollar        |
  168. [Ww]orking{W}[Cc]lass        |
  169. [Ll]ower{W}[Cc]lass        CAP("prole");
  170. ([Ff]ool|[Ii]diot)/s?{EW}    CAP("prole");
  171. [Ss]tupidity            CAP("proleness");
  172.  
  173. %{
  174.     /******************************
  175.      *      Organizations       *
  176.      ******************************/
  177. %}
  178.  
  179. [Aa]?{W}([Ww]hite{W}[Hh]ouse|[Gg]ovt\.?|[Gg]overnment){W}([Ss]ource|[Oo]fficial|[Ss]pokes(man|woman|person))    CAP("an Inner Party Member");
  180. {THE}?[Rr]epublican{W}[Pp]arty        COMP("mini","luv");
  181. {THE}?[Dd]emocratic{W}[Pp]arty        COMP("mini","plenty");
  182.  
  183. {THE}?Congress                    printf("MiniPax");
  184. {THE}?[Ss]enate                    printf("MiniPax");
  185. {THE}?[Hh]ouse{W}[Oo]f{W}[Rr]epresentatives    printf("MiniPax");
  186. {THE}?[Ss]tate{W}[Dd]epartment            printf("MiniPax");
  187. {THE}?[Ss]tate{W}[Dd]ept"."?            printf("MiniPax");
  188. {THE}?[Dd]efen[cs]e{W}[Dd]epartment        |
  189. {THE}?[Dd]efen[cs]e{W}[Dd]ept"."?        |
  190. {THE}?[Ww]ar{W}[Dd]epartment            |
  191. {THE}?[Ww]ar{W}[Dd]ept"."?            |
  192. {THE}?[Hh]ouse{W}of{W}[Cc]ommons        |
  193. {THE}?Pentagon                    |
  194. {THE}?[Ff]eds                    |
  195. {THE}?FCC                    |
  196. {THE}?D[Oo]D                    |
  197. {THE}"D."[Oo]".D."                |
  198. {THE}?[Ss]ecret{W}[Ss]ervice            COMP("mini","luv");
  199. {THE}?White{W}House                |
  200. {THE}?Kremlin                    printf("MiniTrue");
  201. {THE}?(CIA|NSA|FBI|MI"-"?5)/{EW}        printf("MiniTrue");
  202. {THE}?("C.I.A."|"N.S.A."|"F.B.I.")/{EW}        printf("MiniTrue");
  203. {THE}?[Aa]rchive/s?                COMP("mini","rec");
  204. {THE}?[Ll]ibrary                COMP("mini","rec");
  205. {THE}?[Ll]ibraries                COMP("mini","recs");
  206.  
  207. [Tt]hought{W}[Pp]olice|[Nn]azis?        COMP("think","pol");
  208. [Vv]ice{W}[Ss]quad                COMP("sex","pol");
  209. PMRC|"P.M.R.C."                    COMP("sex","pol");
  210.  
  211. [Oo]fficer                    CAP("minister");
  212.  
  213. {THE}?[Dd]epartment{EW}of{EW}.            |
  214. {THE}?[Dd]ept"."?{EW}of{EW}.            |
  215. {THE}?[Uu]niversity{EW}of{EW}.            |
  216. {THE}?[Uu]niv"."?{EW}of{EW}.            |
  217. {THE}?[Dd]ept"."?{EW}of{EW}.            |
  218. {THE}?([Ss]ub"-"?)?[Cc]omm?itt?ee{EW}(of|on){EW}.    |
  219. {THE}?[Ss]chool{EW}of{EW}.            {
  220.     if ((yytext[yyleng-1] >= 'A') && (yytext[yyleng-1] <= 'Z'))
  221.        /* "the school of Law" --> "MiniLaw" */
  222.        printf("Mini%c",yytext[yyleng-1]);
  223.     else if ((yytext[yyleng-1] >= 'a') && (yytext[yyleng-1] <= 'z'))
  224.        /* "the school of law" --> "MiniLaw" (not "Minilaw") */
  225.        printf("Mini%c",yytext[yyleng-1] - ('a' - 'A'));
  226.        /* "the school of 5 things" --> "Ministry of 5 things" */
  227.     else printf("Ministry of %c",yytext[yyleng-1]);
  228.     }
  229.  
  230. [Dd]epartment            |
  231. [Uu]niversity            CAP("ministry");
  232. [Uu]niv"."?/{W}            CAP("ministry");
  233. [Dd]ept"."?/{W}            CAP("ministry");
  234. ([Ss]ub"-"?)?[Cc]omm?itt?ee    CAP("ministry");
  235.  
  236. {THE}[Pp]roject/{EW}        CAP("the Three Year Plan");
  237. [Oo]ur{W}[Pp]roject/{EW}    CAP("our Three Year Plan");
  238. [Bb]udget            printf("Three Year Plan");
  239. [Pp]roject/{ES}            printf("Three Year Plan");
  240.  
  241. {W}({THE}|([aa]{W}))[Pp]roject    printf("%cthe Three Year Plan",Y0);
  242.  
  243. [A-Za-z]+"'"[Ss]/{W}(law|Law|LAW|book|Book|BOOK|rule|Rule|RULE){EW}    printf("Goldstein's");
  244.  
  245. %{
  246.     /******************************
  247.      *         Actions          *
  248.      ******************************/
  249. %}
  250.  
  251. [Ii]n{W}love{EW}    CAP("commiting SexCrime");
  252. [Ll]ove{W}you/{EW}    CAP("love Big Brother");
  253. [Ll]ove{W}me/{EW}    CAP("love Big Brother");
  254.  
  255. [Cc]loning        |
  256. [Rr]eproduction        |
  257. [Cc]elibacy        |
  258. [Pp]rocreation        COMP("good","sex");
  259.  
  260. [Cc]elibate        |
  261. [Pp]rocreate        COMP("good","sexwise");
  262.  
  263. [Tt]elevisions?        |
  264. TVs?            |
  265. [Tt]"."[Vv]"."s?    |
  266. [Rr]adios?        |
  267. [Nn]ews{W}?[Pp]apers?    |
  268. [Jj]ournalism        |
  269. [Mm]ovies?        |
  270. [Rr]ock{EW}?"-"?(and|"&"|"'"?n"'"?){EW}?"-"?[Rr]oll({W}[Mm]usic)?         |
  271. (([Rr]ock|[Cc]lassical|[Ii]ndustrial|[Pp]op|[Dd]ance|[Rr]ap){W})?[Mm]usic    |
  272. [Tt]unes        |
  273. [Mm]oney        |
  274. [Cc]ash            |
  275. [Cc]omic{W}[Bb]ooks?    |
  276. ([Ss]tar{W}?)?[Tt]rek    COMP("prole","feed");
  277.  
  278. [Pp]eace{W}[Mm]ovement        |
  279. [Pp]eace{W}[Pp]rotest        |
  280. [Aa]nti{EW}[Ww]ar        |
  281. ([Pp]assive{W})?[Rr]esistance    |
  282. [Cc]reativity            |
  283. [Tt]reason            |
  284. [Rr]esearch        COMP("crime","think");
  285.  
  286. %{
  287.     /******************************
  288.      *         Religion